public Class ValidationRotingPlanAndVisit_TestClass
{
    static testmethod void test()
    {
        Profile pTsr = [select id from profile where  name = 'Sales Rep - Trade' limit 1];
        Profile pASM = [select id from profile where  name = 'Area/District Sales Manager - Medical' limit 1];
        Profile pDSM = [select id from profile where  name = 'Area/District Sales Manager - Medical' limit 1];
        
        User uASM = new User(alias='standtss', email='sdudfdr@testorgss.com',
        emailencodingkey='UTF-8', lastname='Testeing', languagelocalekey='en_US',
        localesidkey='en_US', profileid=pASM.Id,IsActive=true,
        Title__c='Area/District Sales Manager',FunctionDepartment__c='Trade Sales',
        timezonesidkey='America/Los_Angeles', username='stsdfdfrs@testorg.com');
        insert uASM;
        
        User uDSM = new User(alias='standtss',email='sdusdfer@testorgss.com',ManagerId=uASM.Id,emailencodingkey='UTF-8', lastname='Testeing',
        languagelocalekey='en_US',localesidkey='en_US',timezonesidkey='America/Los_Angeles',profileid=pDSM.Id,
        Title__c='Area/District Sales Manager',FunctionDepartment__c='Trade Sales', 
        username='stserers@testorg.com');
        insert uDSM;
        
        User uTsr = new User(alias='standtss',email='sduser@testorgss.com',emailencodingkey='UTF-8',ManagerId=uDSM.Id, lastname='Testeing',
        languagelocalekey='en_US',localesidkey='en_US',timezonesidkey='America/Los_Angeles',profileid=pTsr.Id,
        Title__c='Sales Rep',FunctionDepartment__c='Trade Sales',
        username='stsers@testorg.com');
        insert uTsr;
        
        User uTsr2 = new User(alias='standtss', email='sdusfsdfer@testorgss.com',
        emailencodingkey='UTF-8', lastname='Testeing', languagelocalekey='en_US',
        localesidkey='en_US', profileid=pTsr.Id,IsActive=true,
        Title__c='Sales Rep',FunctionDepartment__c='Trade Sales',ManagerId=uDSM.Id,
        timezonesidkey='America/Los_Angeles', username='stssfds@testorg.com');
        insert uTsr2;
        
        System.runAs(uTsr)
        {
             Account acc=new Account();
             acc.Name='test';
             acc.Channel__c='特大型综合超市';
             acc.Outlet_Type__c='全国重点客户';
             acc.Contact__c='aaa';
             acc.No_of_checkout__c=22;
             acc.ContactPhoneNumber__c='1234567456';
             acc.OwnerId=uTsr.Id;
             insert acc;
         
            Routing_Plan_And_Visit__c r=new Routing_Plan_And_Visit__c(Visit_Date__c=System.today().addMonths(1),OwnerId=uTsr.Id);
            insert r;
           /* RoutingPlan__c rp=new RoutingPlan__c();
            rp.RoutingPlanAndVisit__c=r.Id;
            rp.OutletName__c=acc.Id;
           // DateTime d=System.today().addMonths(1);
            rp.StartDateTime__c=DateTime.newInstance(r.Visit_Date__c.year(),r.Visit_Date__c.Month(),r.Visit_Date__c.Day(),9,9,9);
            rp.EndDateTime__c=DateTime.newInstance(r.Visit_Date__c.year(),r.Visit_Date__c.Month(),r.Visit_Date__c.Day(),12,12,9);
            insert rp;*/
        }
        
         System.runAs(uASM)
        {
            List<Routing_Plan_And_Visit__c> r=[select Id,Visit_Date__c,OwnerId from Routing_Plan_And_Visit__c where Visit_Date__c=:System.today().addMonths(1)];
            if(r.size() > 0)
                r[0].OwnerId=uTsr2.Id;
          //  r[0].Visit_Date__c=Date.valueOf(r[0].Visit_Date__c).addDays(7);
            update r;
            
           
        }
    }
}